package jast.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.setting.dialect.Props;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Jast
 * @description 配置文件读取
 * @date 2021-02-20 17:52
 */
@Slf4j(topic = "common")
public class Config {
    public static String IP;
    public static String ES_REST_IP;
    public static String INDEX_LIST;
    public static String DATA_SAVE_DIR;
    private static String defaultConfigFile = "es2es.properties";
    public static Props props;

    static {
        init();
    }

    public static void init() {

        String configFile = System.getProperty("user.dir") + "/config/" + defaultConfigFile;
        if (FileUtil.exist(configFile)) {
            props = new Props(configFile);
        } else if (FileUtil.exist(defaultConfigFile)) {
            props = new Props(defaultConfigFile);
        }
        IP = props.getStr("es.ip");
        ES_REST_IP = props.getStr("es.rest.ip");
        INDEX_LIST =props.getStr("es.index.list");
        DATA_SAVE_DIR=props.getStr("es.data.save.dir");
        System.out.println("读取IP："+IP);
        System.out.println("需要写入IP："+ES_REST_IP);
        System.out.println("需要导出索引：");
        for (String index : INDEX_LIST.split(",")) {
            System.out.println(index);
        }
        System.out.println("数据保存目录："+DATA_SAVE_DIR);

    }

}
